package peer;


import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import error.DgoogleException;
import file.RemoteSharedFile;

/**
 * Interface to talk with bootstrap server and remote peers.
 * 
 * @author Iris
 *
 */
public interface IPeerClient {
	
	/** 
	 * Register to boot strap server.
	 * 
	 * @throws DgoogleException
	 */
	void register()  throws DgoogleException;

	/** 
	 * Login to boot strap server.
	 * 
	 * @throws DgoogleException
	 */
	void login()  throws DgoogleException;
	
	/**
	 * Close before you destroy client instance.
	 */
	void close();
	
	/**
	 * Just another name of close.
	 */
	void logoff();

	/**
	 * Reset user password
	 * @throws DgoogleException
	 */
	void resetPassword() throws DgoogleException;
	/**
	 * Send error message
	 * @throws DgoogleException
	 */
	public void error(String type, String details) throws DgoogleException;
	
	/**
	 * Change user password
	 * @throws DgoogleException
	 */
	public void changePassword( String new_pass) throws DgoogleException;
	
	/**
	 * Publish a file to server.
	 * @param path  File path.
	 * @throws DgoogleException 
	 * @throws IOException 
	 */
	void publish(String path) throws DgoogleException, IOException;

	/**
	 * Query files.
	 * @param key_word word to search
	 * @return List of files found.
	 * @throws DgoogleException 
	 */
	List<RemoteSharedFile> query(String key_word) throws DgoogleException;
	
	/**
	 * Download a remote file.
	 * 
	 * @note 
	 * 
	 * There is a flaw in the implementation : when a peer publishes the files with same name,
	 * other peers could only get the last one by this interface.  
	 * This is caused by the protocol limitation.
	 * 
	 * @param file
	 * @return an InputStream to read data of the file.
	 * @throws DgoogleException
	 * @throws IOException
	 */
	InputStream download(RemoteSharedFile file) throws DgoogleException, IOException;
	
	/**
	 * Remove a file from published file list.
	 * @param name file name without path.
	 */
	void unpublish(String name);
}
